-
Notifications
You must be signed in to change notification settings - Fork 9
/
SettingsView.swift
222 lines (212 loc) · 7.85 KB
/
SettingsView.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
//
// SettingsView.swift
// Chord Provider
//
// © 2024 Nick Berendsen
//
import SwiftUI
import ChordProShared
import SwiftlyChordUtilities
/// SwiftUI `View` for the settings
struct SettingsView: View {
/// Chord Display Options
@State private var chordDisplayOptions = ChordDisplayOptions(defaults: AppSettings.defaults)
/// The observable ``FileBrowser`` class
@Environment(FileBrowser.self) private var fileBrowser
/// The app state
@Environment(AppState.self) var appState
/// Dismiss
@Environment(\.dismiss) private var dismiss
/// The body of the `View`
var body: some View {
VStack(spacing: 0) {
Divider()
TabView {
editor
.tabItem {
Label("Editor", systemImage: "pencil")
}
diagram
.tabItem {
Label("Diagrams", systemImage: "guitars")
}
folder
.tabItem {
Label("Songs", systemImage: "folder")
}
options
.tabItem {
Label("Options", systemImage: "music.quarternote.3")
}
}
}
.background(Color.white.colorMultiply(Color.telecaster))
.toolbarBackground(.telecaster)
.task {
chordDisplayOptions.displayOptions = appState.settings.chordDisplayOptions
}
.onChange(of: chordDisplayOptions.displayOptions) {
appState.settings.chordDisplayOptions = chordDisplayOptions.displayOptions
}
}
/// `View` with general options
@ViewBuilder var options: some View {
@Bindable var appState = appState
VStack(alignment: .leading) {
appState.repeatWholeChorusToggle
appState.lyricsOnlyToggle
}
.wrapSettingsSection(title: "General Options")
.frame(maxHeight: .infinity, alignment: .top)
}
/// `View` with diagram display options
var diagram: some View {
VStack {
ScrollView {
VStack(alignment: .leading) {
chordDisplayOptions.fingersToggle
chordDisplayOptions.notesToggle
chordDisplayOptions.mirrorToggle
}
.wrapSettingsSection(title: "General")
VStack(alignment: .leading) {
chordDisplayOptions.playToggle
.frame(maxWidth: .infinity, alignment: .leading)
if chordDisplayOptions.displayOptions.general.showPlayButton {
HStack {
Image(systemName: "guitars.fill")
chordDisplayOptions.midiInstrumentPicker
}
.disabled(!chordDisplayOptions.displayOptions.general.showPlayButton)
.padding([.top, .leading])
}
}
.wrapSettingsSection(title: "MIDI")
}
.frame(maxHeight: .infinity, alignment: .top)
Button(
action: {
chordDisplayOptions.displayOptions = AppSettings.defaults
},
label: {
Text("Reset to defaults")
}
)
.disabled(chordDisplayOptions.displayOptions == AppSettings.defaults)
.padding(.bottom)
}
.animation(.default, value: chordDisplayOptions.displayOptions.general)
}
/// `View` with editor settings
@ViewBuilder var `editor`: some View {
@Bindable var appState = appState
VStack {
ScrollView {
VStack {
HStack {
Text("A")
.font(.system(size: ChordProEditor.Settings.fontSizeRange.lowerBound))
Slider(
value: $appState.settings.editor.fontSize,
in: ChordProEditor.Settings.fontSizeRange,
step: 1
)
Text("A")
.font(.system(size: ChordProEditor.Settings.fontSizeRange.upperBound))
}
.foregroundColor(.secondary)
Picker("Font style", selection: $appState.settings.editor.fontStyle) {
ForEach(ChordProEditor.Settings.FontStyle.allCases, id: \.self) { font in
Text("\(font.rawValue)")
.font(font.font())
}
}
}
.wrapSettingsSection(title: "Editor Font")
VStack {
ColorPickerButtonView(
selectedColor: $appState.settings.editor.chordColor,
label: "Color for **chords**"
)
ColorPickerButtonView(
selectedColor: $appState.settings.editor.directiveColor,
label: "Color for **directives**"
)
ColorPickerButtonView(
selectedColor: $appState.settings.editor.argumentColor,
label: "Color for **arguments**"
)
ColorPickerButtonView(
selectedColor: $appState.settings.editor.markupColor,
label: "Color for **markup**"
)
ColorPickerButtonView(
selectedColor: $appState.settings.editor.bracketColor,
label: "Color for **brackets**"
)
ColorPickerButtonView(
selectedColor: $appState.settings.editor.commentColor,
label: "Color for **comments**"
)
}
.wrapSettingsSection(title: "Highlight Colors")
}
.frame(maxHeight: .infinity, alignment: .top)
Button(
action: {
appState.settings.editor = ChordProEditor.Settings()
},
label: {
Text("Reset to defaults")
}
)
.padding(.bottom)
.disabled(appState.settings.editor == ChordProEditor.Settings())
}
}
/// `View` with folder selector
var folder: some View {
VStack {
ScrollView {
VStack {
Text(.init(Help.folderSelector))
.padding()
Text(.init(Help.macOSbrowser))
.padding()
fileBrowser.folderSelector
.padding()
}
.wrapSettingsSection(title: "The folder with your songs")
}
}
.padding(.bottom)
.frame(maxWidth: .infinity)
}
}
extension SettingsView {
struct WrapSettingsSection: ViewModifier {
let title: String
func body(content: Content) -> some View {
VStack(alignment: .center) {
Text(title)
.font(.headline)
VStack {
content
}
.frame(maxWidth: .infinity)
.padding()
.background(Color.primary.opacity(0.04).cornerRadius(8))
}
.padding([.top, .horizontal])
.frame(maxWidth: .infinity)
}
}
}
extension View {
/// Shortcut to the `WrapSettingsSection` modifier
/// - Parameter title: The title
/// - Returns: A modified `View`
func wrapSettingsSection(title: String) -> some View {
modifier(SettingsView.WrapSettingsSection(title: title))
}
}